package com.qf.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.mapper.DtsRoleMapper;
import com.qf.pojo.DtsRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.test.context.junit.jupiter.EnabledIf;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author Wy
 * @version V1.0
 * @Project MavenDemo
 * @Package com.qf.service
 * @Description:
 * @Date 2022/6/16 14:55
 */
@Service
public class RoleServiceImpl implements  RoleService {

    @Autowired
    private DtsRoleMapper dtsRoleMapper;
    @Override
    public Set<String> queryByIds(Integer[] ids) {

         if(ids==null||ids.length==0 ){
             return new HashSet<String>();
         }
        //创建查询条件对象
        QueryWrapper queryWrapper = new QueryWrapper();
       //模糊查询相当于查询where id in(1,2,3,4)
        queryWrapper.in("id", ids);
        //查询没用被删除的
        queryWrapper.eq("deleted", false);
        //查询启用的角色
        queryWrapper.eq("enabled", true);

        List<DtsRole> list = dtsRoleMapper.selectList(queryWrapper);
        HashSet<String> set = new HashSet<>();
        if(list!=null){
            for (DtsRole o : list) {
                //获取这个对象对应的权限名称
                set.add(o.getName());
            }
        }


        return set;
    }
}
